package com.example.config.batchjob;

import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;


public class MyJobExecutionListener implements JobExecutionListener {

    @Override
    public void beforeJob(JobExecution jobExecution) {
        // 可以在这里添加作业开始前的逻辑
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        if (jobExecution.getStatus() == BatchStatus.FAILED) {
            System.out.println("Job: [" + jobExecution.getJobInstance().getJobName() + 
                               "] completed with the following parameters: " + 
                               jobExecution.getJobParameters() + 
                               " and the following status: [FAILED]");
            
            // 在这里可以添加更详细的错误处理逻辑，例如日志记录或通知机制
        }
    }
}